import tornado.web
from tornado.web import StaticFileHandler, URLSpec

import config
from config import settings
from views import *

"""
    创建Application
"""


class MainApplication(tornado.web.Application):
    def __init__(self):
        # BASE HANDLERS
        handlers = [
            # 静态文件
            URLSpec(r"/static/(.*)", StaticFileHandler, {"path": config.STATIC_ROUTERS_CONFIGS["STATIC_PATH"]}),
            URLSpec(r"/css/(.*)", StaticFileHandler, {"path": config.STATIC_ROUTERS_CONFIGS["CSS_URL"]}),
            URLSpec(r"/js/(.*)", StaticFileHandler, {"path": config.STATIC_ROUTERS_CONFIGS["JS_URL"]}),
            URLSpec(r"/img/(.*)", StaticFileHandler, {"path": config.STATIC_ROUTERS_CONFIGS["IMG_URL"]}),
        ]
        # SERVICE HANDLERS
        handlers.extend(all_router_configs())
        super().__init__(handlers=handlers, **settings)
        print("******tornado web application configs******")
        print("handlers", handlers)
        print("setting", config.settings)
